package com.example.demo.commen;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
public class AppResult<T> {

    @JsonInclude(JsonInclude.Include.ALWAYS)    //无论是否为空，这个属性都会参加json序列化，（不论你空不空，都会给前端返回的）
    int code;

    @JsonInclude(JsonInclude.Include.ALWAYS)
    String message;
    @JsonInclude(JsonInclude.Include.ALWAYS)
    T data;

    public static <T>AppResult<T> success(T data){
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.SUCCESS.getCode());
        appResult.setMessage(ResultCode.SUCCESS.getMessage());
        appResult.setData(data);
        return appResult;
    }

    public static AppResult success(){
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.SUCCESS.getCode());
        appResult.setMessage(ResultCode.SUCCESS.getMessage());
        appResult.setData("");
        return appResult;
    }

    public static AppResult failed(String message){
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.FAILED.getCode());
        appResult.setMessage(message);
        System.out.println("这里是测试");
        appResult.setData("");
        System.out.println(appResult);
        return appResult;
    }

    public static AppResult failed(){
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.FAILED.getCode());
        appResult.setMessage(ResultCode.FAILED.getMessage());
        appResult.setData("");
        return appResult;
    }

    public static AppResult failed(AppResult appResult1){
        AppResult appResult = new AppResult();
       appResult.setCode(appResult.getCode());
       appResult.setMessage(appResult.getMessage());
       appResult.setData(appResult.data);
        return appResult;
    }


}
